﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using Excel = Microsoft.Office.Interop.Excel;

namespace QuickExcel
{
    public partial class ExportChart : Form
    {
        public ExportChart()
        {
            InitializeComponent();
        }

        private void ExportChart_Load(object sender, EventArgs e)
        {
            if (Globals.ThisAddIn.Application.ActiveChart == null)
            {
                MessageBox.Show("Please select the chart and Try Again");
                this.Close();
            }
            else
                txtNameChart.Text = Globals.ThisAddIn.Application.ActiveChart.Name;
        }

        private void txtSaveAs_Click(object sender, EventArgs e)
        {
            ExportCharttoImage.ShowDialog();
            txtSaveAs.Text = ExportCharttoImage.FileName;
        }

        private void cmdCancel_Click(object sender, EventArgs e)
        {
            this.Close();
        }

        private void cmdOK_Click(object sender, EventArgs e)
        {
            Globals.ThisAddIn.Application.ActiveChart.Export(txtSaveAs.Text);
            MessageBox.Show("Chart Exported as Filename: " + txtSaveAs.Text);
            this.Close();
        }
    }
}
